//
//  WalletCoinListCell.swift
//  SCA
//
//  Created by tjun on 2025/9/4.
//

import UIKit
import SnapKit



class WalletInfo {
    
    let coinModels: [WalletCoinModel]
    let total: String
    let total_disp: String
    let deposit: Bool
    let withdraw: Bool
    let transfer: Bool
    let swap: Bool
    
    init(coinModels: [WalletCoinModel], total: String, total_disp: String, deposit: Bool, withdraw: Bool, transfer: Bool, swap: Bool) {
        self.coinModels = coinModels
        self.total = total
        self.total_disp = total_disp
        self.deposit = deposit
        self.withdraw = withdraw
        self.transfer = transfer
        self.swap = swap
    }
}


class WalletCoinModel {
    let coin: String
    let coinName: String
    let coinUrl: String
    let amount: String
    let stacked: String
    let locked: String
    let useable: String
    let transferable: String
    let balance: String
    let value: String
    let price: String
    let transfer: Bool
    let withdraw: Bool
    
    init(coin: String, info: [String: String], coinUrl: String, transfer: Bool, withdraw: Bool) {
        self.coinUrl = coinUrl
        self.coin = coin
        self.coinName = info.stringValue("title")
        self.amount = info.stringValue("amount")
        self.stacked = info.stringValue("stacked")
        self.locked = info.stringValue("locked")
        self.useable = info.stringValue("useable")
        self.transferable = info.stringValue("transferable")
        self.balance = info.stringValue("balance")
        self.value = info.stringValue("value")
        self.price = info.stringValue("price")
        self.transfer = transfer
        self.withdraw = withdraw
    }
}

class WalletCoinListCell: BaseTableViewCell {

    private let iconImageView = UIImageView()
    private let iconNameLabel = UILabel(text: "SCA", font: UIFontSemiboldMake(16), textColor: .white)
    private let coinValueLabel = UILabel(text: "@1.2", font: UIFontSemiboldMake(13), textColor: .gray)
    private let totalValueLabel = UILabel(text: "60,126.21", font: UIFontSemiboldMake(16), textColor: .white)
    private let totalUSDTValueLabel = UILabel(text: "$60,126.21", font: UIFontSemiboldMake(13), textColor: .gray)
    
    var model: WalletCoinModel! {
        didSet {
            iconImageView.setImage(url: model.coinUrl)
            iconNameLabel.text = model.coinName
            coinValueLabel.text = model.price
            totalValueLabel.text = model.amount
            totalUSDTValueLabel.text = model.value
        }
    }
    
    override func setSubView() {
        super.setSubView()
        
        
        self.selectedBackgroundView = UIView()
        selectCellBackgroundColor = UIColorMake(0x14161A)
        
        backgroundColor = AppStyle.color.background
        
        contentView.addSubviews(iconImageView, iconNameLabel, coinValueLabel, totalValueLabel, totalUSDTValueLabel)
        iconImageView.snp.makeConstraints { make in
            make.left.equalTo(AppStyle.margin.left)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(40)
        }
        
        iconNameLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(iconImageView)
        }
        
        coinValueLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.bottom.equalTo(iconImageView)
        }
        
        totalValueLabel.snp.makeConstraints { make in
            make.right.equalTo(-AppStyle.margin.left)
            make.centerY.equalTo(iconNameLabel)
        }
        
        totalUSDTValueLabel.snp.makeConstraints { make in
            make.right.equalTo(totalValueLabel)
            make.centerY.equalTo(coinValueLabel)
        }
    }

}
